#pragma once

#include <string>

#include "DoubleLinkedList.h"
#include <windows.h>
#include <time.h>
#include "textfile.h"
#include "hpsutils.h"
#include "Strsafe.h"
#include "Config.h"

using namespace std;

#define DEFAULT_PLAYLIST_FILE L"playlist.pls"


struct MusicFileData 
{
	wstring	name;			// Dainos pavadinimas.
	wstring	filePath;		// PILNAS adresas iki failo
	int		length;			// trukme sekundemis
};


class PlayList
{
private:
	int									mCurrentSongNR;						// Dabartines dainos irasas
	DoubleLinkedList<MusicFileData>		mFileList;							// dainu sarasas
	DoubleLinkedList<int>				mPlayableFileList;					// Grojamas sarsas kai dainos ismaisytos
	TextFile*							mTFin;								// Skaitymui
	TextFile*							mTFout;								// Rasymui
	bool								mIsShuffled;
	bool								mAddRunning;
	bool								mSortDirection;
	Config*								mConfig;
	// dar reiks paziuret koks playlistas uzloadintas

public:
	PlayList( Config *config ) 
	{
		mConfig = config;
		mIsShuffled = false;
		mCurrentSongNR = -1;
		srand( time(0));
		mTFin = new TextFile;
		mTFout = new TextFile;
	}

	~PlayList()
	{
		mFileList.clear();
		mPlayableFileList.clear();
		delete mTFin;
		delete mTFout;
	}

	void add(MusicFileData data);
	//void setAddRunning(bool status);						// Kai pradedami prideti failai, nustatomas true

	//grazinti viska


	void shuffle(bool findSong, bool nullCurrentSong = false);
	void unShuffle();
	void setShuffle(bool shuffled, bool nullCurrentSong = false);
	bool isShufled();

	void sortByName(bool direction);		// True - abcd, false atvirksciai
	int random(int low, int high);
	int playListFileData( wstring FileName, int &version, int &numberOfEntries );

	void			updateSongData(int id, wstring songName, int songLength);
	void			deleteSong(int id);
	void			setSongPlace(int id);
	int				getCurrentSongId();  // Jei true ignoruoja randomizinimo masyvo id.
	MusicFileData	getSong(int id);
	MusicFileData	getSongForDrawing(int id);
	MusicFileData	getCurrentSong();
	MusicFileData	next();					// Gauna sekancia daina
	MusicFileData	prev();					// Gauna praeita daina
	
	int count();							// grazina dainu skaiciu

	void loadPlaylist(wstring filePath);
	void LoadDefaultPlaylist();
	void savePlayList( wstring filePath );
	bool FileExists(const wstring path, const wstring fileName);
	bool FileExists(const wstring path);

	void tralialia();
	void log(int sk, int kokia);

	void clearPlaylist();
}; 